public class LeetCode0719 {
    public static void main(String[] args) {
        int[] nums = {7,0,9,6,9,6,1,7,9,0,1,2,9,0,3};
        System.out.println(jump(nums));
    }

    public static int jump(int[] nums) {
        if(nums.length==1){
            return 0;
        }
        int index=nums[0];
        int maxIndex=index;
        int count=1;
        for (int i = 0; i <nums.length-1&&maxIndex<nums.length-1; i++) {
            if(index<i+nums[i]){
                maxIndex = i+nums[i];
                int temp = maxIndex;
                while (i<=index){
                    if(i+nums[i]>maxIndex){
                        maxIndex=i+nums[i];
                    }
                    i++;
                }
                    i--;
                count++;
                index = maxIndex;
            }
        }
        return count;
    }
}
